/*  

Cafechess Library: Cover basic chess programming needs, like GUI, Engine integration, 
FEN and PGN parsing.

                 \\|//
                 (o o)
--------------ooO-(_)-Ooo----------------------------------
Copyright (C) 2009  By Gregory A. Prentice Snoqualmie, WA
                    www.cafechess.org
                    cafechess@comcast.net
                      Oooo
--------------oooO----(  )---------------------------------
              (  )    (_/
               \_)

Microsoft Public License (Ms-PL)
               
Revisions:

Author        Date    Description:

*/
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace Cafechess.Imaging.Draw
{
	/// <summary>
	/// Summary description for DrawSquare.
	/// </summary>
  public class DrawSquare : DrawOnMouseEvents
  {
    public DrawSquare(System.Windows.Forms.Control aControl) : base(aControl)
    {
      coPen = new Pen(Color.Blue, 1);
      coPen.Alignment = PenAlignment.Inset;
    }
    public DrawSquare(System.Windows.Forms.Control aControl,Color color, int width) : base(aControl)
    {
      coPen = new Pen(color, width);
      coPen.Alignment = PenAlignment.Inset;
    }

    override public void DrawFinished(Graphics g)
    {
      if( EndPoint.X > StartPoint.X && EndPoint.Y > StartPoint.Y )
      {
        g.DrawRectangle(coPen,StartPoint.X, StartPoint.Y,
          EndPoint.X - StartPoint.X,EndPoint.Y - StartPoint.Y);
      }
      else
      {
        g.DrawRectangle(coPen,EndPoint.X, EndPoint.Y,
          StartPoint.X - EndPoint.X,StartPoint.Y - EndPoint.Y);

      }
    }
    override public bool HitTest(Point point)
    {
      return Square.Contains(point);
    }
  }
}
